library(margins)

lm0 = ( lm('ListOut ~ ListFavor*SocDens',
           data = A[which(A$ListTreat != 2),]) ) #

#make margins plot for no-controls regression; neighborhood clustering
lm0_mar_clus = margins(lm0, at = list(SocDens=c(-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1)),
                       vcov = cluster.vcov( lm0, A[which(A$ListTreat != 2),'A.A7_Area.Neighborhood'] ) )
a = summary(lm0_mar_clus) %>% filter(factor == 'ListFavor')
ggplot(aes(x = SocDens), data = a) + geom_point(aes(y = AME)) + geom_errorbar(aes(ymin = lower, ymax = upper)) +
  xlab('Individual Connectedness') + ylab('AME of Individual-Clientelism Treatment') + theme_bw() +
  ggtitle('Individual Clientelism and Individual Connectedness', subtitle =  'No Controls')
ggsave(path = '../results/',
              filename = paste0('FigA1_',(Sys.time() %>% str_replace_all(c(":" = "-", " " = "_"))),'.jpg'),
              device = 'jpeg')

rm(a, lm0, lm0_mar_clus) 